/**
 * @author wujx
 *  const_rootUrl根目录 = ${rootUrl} 
 *  实例：使用地址页面上需要有 id 为 
 *  <select id="province" > </select> 
 *  <select id="city"> </select> 
 *  <select id="country"> </select>
 *  3个控件
 * 
 */
$(function() {
	var theProvinceSelect = document.getElementById("province");
	$.ajax({
		url : const_rootUrl+"/info/area!getProvice",
		processData : false,
		data : null,
		success : function(data) {
			for ( var obj in data) {
				theProvinceSelect.options.add(new Option(data[obj].name,
						data[obj].id));
			}
		}
	});
	$("#province").change(function(){
		var provinceId = $("#province").val();
		var theCitySelect = document.getElementById("city");
		var theCountrySelect = document.getElementById("country");
		theCountrySelect.innerHTML = "";
		theCitySelect.innerHTML = "";
		theCountrySelect.options.add(new Option("",""));
		$.ajax({
			url : const_rootUrl+"/info/area!getCity",
			processData : false,
			data : "areaId="+provinceId,
			success : function(data) {
				for ( var obj in data) {
					theCitySelect.options.add(new Option(data[obj].name,
							data[obj].id));
				}
				//通过市获取县
				var theCountrySelect = document.getElementById("country");
				theCountrySelect.innerHTML = "";
					$.ajax({
						url : const_rootUrl + "/info/area!getCountry",
						processData : false,
						data : "areaId=" + $("#city").val(),
						success : function(data) {
							for ( var obj in data) {
								theCountrySelect.options.add(new Option(
										data[obj].name, data[obj].id));
							}
						}
					});
			}
		});
	});
	$("#city").change(function(){
		var cityId = $("#city").val();
		var theCountrySelect = document.getElementById("country");
		theCountrySelect.innerHTML = "";
		$.ajax({
			url : const_rootUrl+"/info/area!getCountry",
			processData : false,
			data : "areaId="+cityId,
			success : function(data) {
				for ( var obj in data) {
					theCountrySelect.options.add(new Option(data[obj].name,
							data[obj].id));
				}
			}
		});
	});
});